Φαντάζομαι θέλεις να αποφύγεις την ενδιάμεση δημιουργία του αρχείου στο δίσκο συγκριτικά με την μέθοδο που ακολούθησες.Με δεδομένο ότι έχεις έτοιμη την εικόνα σου σε ένα System.Drawing.Image αντικείμενο:
void cam_ImageCaptured(object source, WebCam_Capture.WebcamEventArgs e)
{
//h abstract klash System.Drawing.Image de mas einai kai poly xrhsimh apo monh ths
System.Drawing.Bitmap bmp=new System.Drawing.Bitmap(e.WebCamImage);
//pairnoume ta bits tou bitmap mas
System.Drawing.Imaging.BitmapData bmpData= bmp.LockBits(new System.Drawing.Rectangle(0,0,bmp.Width,bmp.Height),System.Drawing.Imaging.ImageLockMode.WriteOnly,bmp.PixelFormat);
//kai fylame dyo times pou mas endiaferoun
IntPtr ptr=bmpData.Scan0; int stride = bmpData.Stride;
int size=bmpData.Stride*bmpData.Height;
//xreiazomaste thn paletta me ta xrwmata(pleonasmos edw alla sthn para8etw gia plhrothta)
List<Color> colors = new List<Color>();
foreach (System.Drawing.Color bmpcolor in bmp.Palette.Entries)
{ colors.Add(new Color { A = bmpcolor.A, B = bmpcolor.B, R = bmpcolor.R, G = bmpcolor.G }); }
BitmapPalette palette=colors.Count==0?null: new BitmapPalette(colors);
//o idios pleonasmos gia to PixelFormat ths eikonas (an to ksereis apo prin antikatesthse monos sou thn timh anti gia to parakatw tmhma kwdika)
PixelFormat pixelFormat;
switch (bmp.PixelFormat)
{
case System.Drawing.Imaging.PixelFormat.Format16bppRgb555: pixelFormat = PixelFormats.Bgr555;
break;
case System.Drawing.Imaging.PixelFormat.Format16bppRgb565 :
pixelFormat = PixelFormats.Bgr565;
break;
case System.Drawing.Imaging.PixelFormat.Format24bppRgb :
pixelFormat = PixelFormats.Bgr24;
break;
case System.Drawing.Imaging.PixelFormat.Format32bppRgb :
pixelFormat = PixelFormats.Bgr32;
break;
case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
pixelFormat = PixelFormats.Bgra32;
break;
default:
pixelFormat = PixelFormats.Bgr24;
break;
}
//twra dhmiourgoume to source tou image control me bash tis idiothtes tou parapanw bitmap
BitmapSource bmpsrc = BitmapSource.Create(bmp.Width, bmp.Height, bmp.HorizontalResolution, bmp.VerticalResolution, pixelFormat, palette, bmpData.Scan0, size, stride); bmp.UnlockBits(bmpData);
//epitelous exoume etoimo to source tou image control
image.Source = bmpsrc;
}
Ελπίζω αυτή η λύση να σε κάλυψε :)